// Copyright (c) Appeon
// The following has been modified by Appeon under compliance with the Apache 2.0 license from the original work

// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System.Data;
using System.Data.Common;
using Microsoft.Data.SqlClient;
using JetBrains.Annotations;

namespace SnapObjects.Data.SqlServer
{
    public class SqlServerTimeSpanTypeMapping : TimeSpanTypeMapping
    {
        public SqlServerTimeSpanTypeMapping([NotNull] string storeType, [CanBeNull] DbType? dbType = null)
            : base(storeType, dbType)
        {
        }

        protected override void ConfigureParameter(DbParameter parameter, IAdoDbParameter adoDbParameter)
        {
            base.ConfigureParameter(parameter, adoDbParameter);

            // Workaround for a SQLClient bug
            if (this.DbType == System.Data.DbType.Time)
            {
                ((SqlParameter)parameter).SqlDbType = SqlDbType.Time;
            }
        }
    }
}
